package jee.boot.entity.auth;

import jee.boot.common.annotation.Table;
import jee.boot.common.basic.Page;
import jee.boot.common.basic.interceptor.impl.DefaultPreInsertInterceptor;
import jee.boot.common.basic.interceptor.impl.DefaultPreQueryInterceptor;
import jee.boot.common.basic.interceptor.impl.DefaultPreUpdateInterceptor;
import jee.boot.entity.system.BasicObj;
import jee.boot.entity.system.TreeAsignSituation;

/**
 * 列
 */
@Table(name = "mt_column")
public class Column extends BasicObj<Column> {
    /**
     * type字典
     * DIC_MT_ColumnType_CT01	维度
     * DIC_MT_ColumnType_CT02	度量
     * DIC_MT_ColumnType_CT03	主键
     * DIC_MT_ColumnType_CT99	其它
     */
    private static final long serialVersionUID = 1L;
    /**
     * 数据库列名
     */
    @jee.boot.common.annotation.Column(name = "st_column_name")
    private String columnName;
    /**
     * 模型ID
     */
    @jee.boot.common.annotation.Column(name = "st_model_id",data = {"modelData.id","modelData.no","modelData.code","modelData.name","modelData.desc","modelData.type","modelData.modelTableName"})
    private ModelData modelData;//引用：MT_MODEL
    /**
     * 超类ID
     */
    @jee.boot.common.annotation.Column(name = "st_super_id",data = {"superColumn.id","superColumn.no","superColumn.code","superColumn.name","superColumn.desc","superColumn.type"})
    private Column superColumn;//引用：MT_COLUMN
    /**
     * 虚拟标志
     */
    @jee.boot.common.annotation.Column(name = "st_virtual_flag")
    private String virtualFlag;//字典：DIC_SYS_YesNo，用于预定义的不用于业务使用的超类对象
    /**
     * 值域类型
     */
    @jee.boot.common.annotation.Column(name = "st_data_domain_type")
    private String dataDomainType;//字典：DIC_SYS_DataDomainType
    /**
     * 值域
     * //    当ST_DATA_DOMAIN_TYPE='DIC_SYS_DataDomainType_DDT01'时，此处存储数据字典组的KEY(例如：'DIC_MD_SupplierStatus')；
     * //    当ST_DATA_DOMAIN_TYPE='DIC_SYS_DataDomainType_DDT02'时，此处存储主数据的MODEL(例如：'mtPorg')；
     * //    当ST_DATA_DOMAIN_TYPE='DIC_SYS_DataDomainType_DDT04'时，此处引用：ST_TREE_MODEL"
     */
    @jee.boot.common.annotation.Column(name = "st_data_domain")
    private String dataDomain;
    /**
     * 值域外键,当值域类型选择主数据的时候,需要把主数据的外键(常规都是用id进行关联的,但部分项目会使用code进行管理,这时候就需要指定外键)记录下,默认id
     */
    @jee.boot.common.annotation.Column(name = "st_data_domain_fk")
    private String dataDomainFk="id";
    /**
     * 值域过滤条件
     */
    @jee.boot.common.annotation.Column(name = "st_data_domain_filter")
    private String dataDomainFilter;//如果系统无法区分多个同表Model，则需要用此字段存储Model的过滤条件，数据格式举例：{left: "stEmployeeName", operate: "like", right: "asdf"}。当ST_CONTROL_DATA_DOMAIN_TYPE='DIC_SYS_DataDomainType_DDT04'时，此字段无值
    /**
     * 树定位情境ID
     */
    @jee.boot.common.annotation.Column(name = "st_tree_asign_situation_id",data = {"treeAsignSituation.id","treeAsignSituation.no","treeAsignSituation.code","treeAsignSituation.name","treeAsignSituation.desc","treeAsignSituation.type"})
    private TreeAsignSituation treeAsignSituation;//引用：ST_TREE_ASIGN_SITUATION，当ST_CONTROL_DATA_DOMAIN_TYPE='DIC_SYS_DataDomainType_DDT04'时，此字段才有值
    /**
     * 列显示使用的元数据定义,定义列的显示宽度,样式等信息
     */
    @jee.boot.common.annotation.Column(name="st_meta")
    private String meta;
    /**
     * 排序字段
     */
    private Integer sort=0;
    public Column() {
    }

    public Column(String id) {
        super(id);
    }

    public Column(String columnName, String code) {
        this.columnName = columnName;
        setCode(code);
    }

    public ModelData getModelData() {
        return modelData;
    }

    public void setModelData(ModelData modelData) {
        this.modelData = modelData;
    }

    public Column getSuperColumn() {
        return superColumn;
    }

    public void setSuperColumn(Column superColumn) {
        this.superColumn = superColumn;
    }

    public String getVirtualFlag() {
        return virtualFlag;
    }

    public void setVirtualFlag(String virtualFlag) {
        this.virtualFlag = virtualFlag;
    }

    public String getDataDomainType() {
        return dataDomainType;
    }

    public void setDataDomainType(String dataDomainType) {
        this.dataDomainType = dataDomainType;
    }

    public String getDataDomain() {
        return dataDomain;
    }

    public void setDataDomain(String dataDomain) {
        this.dataDomain = dataDomain;
    }

    public String getDataDomainFilter() {
        return dataDomainFilter;
    }

    public void setDataDomainFilter(String dataDomainFilter) {
        this.dataDomainFilter = dataDomainFilter;
    }

    public TreeAsignSituation getTreeAsignSituation() {
        return treeAsignSituation;
    }

    public void setTreeAsignSituation(TreeAsignSituation treeAsignSituation) {
        this.treeAsignSituation = treeAsignSituation;
    }

    public String getColumnName() {
        return columnName;
    }

    public void setColumnName(String columnName) {
        this.columnName = columnName;
    }

    public String getMeta() {
        return meta;
    }

    public void setMeta(String meta) {
        this.meta = meta;
    }

    public Integer getSort() {
        return sort;
    }

    public void setSort(Integer sort) {
        this.sort = sort;
    }

    public String getDataDomainFk() {
        return dataDomainFk;
    }

    public void setDataDomainFk(String dataDomainFk) {
        this.dataDomainFk = dataDomainFk;
    }

    @Override
    public Page<Column> getPage() {
        Page<Column> page = super.getPage();
        if(page==null){
            page=new Page<>();
            page.setOrderBy("sort");
            page.setOrderSort("asc");
        }
        return page;
    }

    @Override
    public void preInsert() {
        new DefaultPreInsertInterceptor().execute(this);
    }
    @Override
    public void preUpdate() {
        new DefaultPreUpdateInterceptor().execute(this);
    }
    @Override
    public void preQuery() {
        new DefaultPreQueryInterceptor().execute(this);
    }
}
